/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#shoufeijl-chaxun").trigger('click'); 
		return false;
		}
	});
});
//查询条件定义
var kaishisj ='';
var jieshusj =  '';
var xingmingsj = '';
//定位变量
var pageNumber=1;
var sfdingweiid='';
var dingwei='';
var dwpanduan=true;
var dwkaishisj='';
var dwjieshusj='';
var dwxingmingsj='';

var huanzheid='';
//获取详情和退费的收费记录ID传值Fjh
var isYiBao = false;
function getSfdingwei(presfid,prepageNo,prekaishisj,prejieshusj,prexingmingsj, preisYiBao) {
	sfdingweiid = presfid;
	dwkaishisj = prekaishisj;
	dwjieshusj = prejieshusj;
	dwxingmingsj = prexingmingsj;
	isYiBao = preisYiBao;
	if(prepageNo != null && prepageNo != '' && prepageNo != 'null') {
		pageNumber = prepageNo;
	}
}
$(function(){
	$("#changygn").css({"border-bottom":"solid 4px #097c25","height":"60px"});
});

//初始时间获取方法
function getShijian(prekaishisj,prejieshusj){
	//重置查询条件
	$("#sfjl-chongzhibtn").click(function(){
	    $("#chaxtj-sfjl-xingmingsj").val("");
	    $('#sfjl-kaishjsj').val(prekaishisj);
	    $('#sfjl-jieshusj').val(prejieshusj);
	//    查询条件重置后进行查询
	    if(prekaishisj!=null){
			kaishisj=prekaishisj;
		    jieshusj=prejieshusj;
		    xingmingsj='';
		    dwpanduan=false;
		    pageNumber=1;
		    getShoufeijl();
		}
	});
//	进入页面进行查询
	if(prekaishisj!=null){
		if(dwxingmingsj!=''&&dwxingmingsj!='null'){
			xingmingsj=dwxingmingsj;
			$("#chaxtj-sfjl-xingmingsj").val(dwxingmingsj);
		}else {
			xingmingsj='';
		}
		if(dwkaishisj!=''&&dwkaishisj!='null'){
			kaishisj=dwkaishisj;
			jieshusj=dwjieshusj;
			$('#sfjl-kaishjsj').val(kaishisj);
			$('#sfjl-jieshusj').val(jieshusj);
		}else{
			kaishisj=prekaishisj;
			jieshusj=prejieshusj;
		}
	    getShoufeijl();
	}
}
//收费记录点击查询
$(".shoufjl .obtn1").click(function(){
    xingmingsj = $("#chaxtj-sfjl-xingmingsj").val();
    kaishisj = $('#sfjl-kaishjsj').val();
    jieshusj = $('#sfjl-jieshusj').val();
    dwpanduan=false;
    pageNumber=1;
    getShoufeijl();
});


function getShoufeijl(){
	var totalNumber = 0;
	var params={
		kaishisj:kaishisj,
		jieshusj:jieshusj,
		xingmingsj:xingmingsj
	};
	$.ajax({
	    type:"get",
	    //获取json文件路径
	    url:"../chaxuntjsfjl/getCount",
	    //传送数据
	    data:params,
	    async:false,
	    //请求成功完成后要执行的方法
	    success: function(data){
	    		totalNumber = data;
	    		if(totalNumber==0){
					$("#chxtjsfjl-tbneirong").css("display","none");
					$("#sf-img").html("<img src='"+path+"/image/cxtj-nobody.png'>");
				}else{
					$("#chxtjsfjl-tbneirong").css("display","block");
					$("#sf-img").html("");
				}
	    }
	});
	function createDemo(name) {
	    dwxingmingsj=$("#chaxtj-sfjl-xingmingsj").val();
		$('#tbshoufeijl').html('');
	  var container = $('#pagination-'+name);
	  container.pagination({
	    dataSource:'../chaxuntjsfjl/getByPage?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&xingmingsj='+xingmingsj,
	    locator: 'entities',
	    pageSize: 12,
	    pageNumber:pageNumber,
	    totalNumber: totalNumber,
	     //增加总记录数
		showNavigator: true,
   	    formatNavigator: '共 <%= totalNumber %> 条',
	    callback: function(data, pagination) {
	    	var dataHtml ="";
	        $.each(data, function (index, item) {
	        	var nianling = this.nianling;
				var nianlingdw = this.nianlingdw;
				nianling = nianling + nianlingdw;
				if(this.nianling==null) {
					nianling = '';
				}
				var xingbie = this.xingbie;
				if(xingbie==1) {
					xingbie = '男';
				}else if(xingbie==2) {
					xingbie = '女';
				}else{
					xingbie = '';
				}
				var shishouje='';
				index = ((pagination.pageNumber-1)*pagination.pageSize)+index+1;
	        	dataHtml += '<tr class="user" id="sfhang'+index+'">';
	        	dataHtml += '<td> ' + index + '</td>';
	            dataHtml += '<td class="left"><span class="icon-user" title="进入患者详情" onclick=getHuanzhe('+this.huanzheid+')></span>' + item.xingming + '</td>';
	            dataHtml += '<td>' + xingbie + '</td>';
	            dataHtml += '<td>' + nianling + '</td>';
	            dataHtml += '<td>' + item.shoufeisjstr + '</td>';
	            dataHtml += '<td class="left">' + item.jibingmc + '</td>';
	            dataHtml += '<td>' + item.yishengmc + '</td>';
	            dataHtml += '<td class="right">' + item.zhehouje.toFixed(2) + '</td>';
	            dataHtml += '<td class="right">' +item.shishouje.toFixed(2)+ '</td>';
	            dataHtml +='<td>';
	            dataHtml +='<div class="table-operation">';
	            var showTuifei = true;
	            if(this.isDaijianwp == 1 || this.daijianzt == '4' || this.daijianzt == '7'){
	            	showTuifei = false;
	            }
	            dataHtml +='<span class="obtn3" onclick="toShoufeijlxq('+this.id+','+pagination.pageNumber+','+showTuifei+')">详情</span>';
	            if(this.tuifeijlid==null&&this.qianfeijlid==null) {
	            	if( this.daijianzt != '4' && this.daijianzt != '7') {
	            		dataHtml +='<span class="obtn4" onclick="toShoufeijltk('+this.id+','+pagination.pageNumber+','+this.yibaojsid+')">退费</span>';
	            	}else if(this.isDaijianwp == 0) {
	            		dataHtml +='<span class="obtn4" onclick="toShoufeijltk('+this.id+','+pagination.pageNumber+','+this.yibaojsid+')">退费</span>';
	            	}
				}
				if(this.tuifeijlid!=null){
					dataHtml +='<span class="obtn5" onclick="toTuifeijlxq('+this.id+','+this.tuifeijlid+','+pagination.pageNumber+')">已退费</span>';
				}
				dataHtml +='</div></td></tr>';
				
				//查询状态定位判断Fjh
				if(sfdingweiid==this.id){
					dingwei=index;
	        	}
	        });
	        $('#tbshoufeijl').html(dataHtml);
	        //查询状态定位Fjh
	        if(dingwei!=null&&dingwei!=''){
	 	        $('#tbshoufeijl').find('tr[id="sfhang'+dingwei+'"]').addClass('list-tr');
	        }
			//点击查询按钮和重置按钮定位状态消失
	        if(!dwpanduan){
	        	$('#tbshoufeijl').find('tr[id="sfhang'+dingwei+'"]').removeClass('list-tr');
	        }
	  	}
	  });
	  return container;
	}
	createDemo('fenysfjl');
	if(totalNumber <= 12) {
		$('#pagination-fenysfjl').css('display','none');
	}else{
		$('#pagination-fenysfjl').css('display','block');
	}
}
// 跳转进收费记录详情
function toShoufeijlxq(id,prepageNo,showTuifei) {
	var predwxingmingsj =encodeURI(encodeURI(dwxingmingsj));
	$('.cxtj-neirk').load(path+ "/views/chaxun-tongji/chaxtj-sfxq.jsp?yemianrk=shoufeijl&ID="+id+"&pageNo="+prepageNo+"&kaishisj="+kaishisj+"&jieshusj="+jieshusj+"&dwxingmingsj="+predwxingmingsj+"&showTuifei="+showTuifei);
}

// 跳转进收费记录退款
function toShoufeijltk(shoufeiid, prepageNo, preyibaojsid) {
	if (!isYiBao && preyibaojsid != null) {
		notifyWarning('请开启医保开关，再操作退费业务');
		return false;
	}
	if (isYiBao && preyibaojsid != null && $('#isKehud').val() == 0) {
		notifyWarning('请下载医箱客户端再操作退费业务');
		return false;
	} 
	var predwxingmingsj =encodeURI(encodeURI(dwxingmingsj));
	$('.cxtj-neirk').load(path+ "/views/chaxun-tongji/chaxtj-tfxq.jsp?shoufeiid="+shoufeiid+"&pageNo="+prepageNo+"&dwkaishisj="+kaishisj+"&dwjieshusj="+jieshusj+"&dwxingmingsj="+predwxingmingsj+'&yemianrk=shoufeijl');
}

// 跳转进退费记录详情
function toTuifeijlxq(shoufeiid,tuifeiid,prepageNo) {
	var predwxingmingsj =encodeURI(encodeURI(dwxingmingsj)); 
	$('.cxtj-neirk').load(path+ "/views/chaxun-tongji/chaxtj-tfjl-tfxq.jsp?yemianrk=shoufeijl&ID="+tuifeiid+"&shoufeiid="+shoufeiid+"&pageNo="+prepageNo+"&dwkaishisj="+kaishisj+"&dwjieshusj="+jieshusj+"&dwxingmingsj="+predwxingmingsj);
}